import { Component, OnInit } from '@angular/core';
import * as _ from 'lodash'
import * as echarts from 'echarts';
import { ScaleService } from "./scale.service";

@Component({
  selector: 'app-scale',
  templateUrl: './scale.component.html',
  styleUrls: ['./scale.component.scss'],
  providers: [ScaleService]
})
export class ScaleComponent implements OnInit {
  // 资产规模数据
  public dataList: any = [];
  // 产品内码
  public nFundNo: any;

  constructor(
    public scaleService: ScaleService
  ) { }

  ngOnInit() {
  }
  ngAfterViewInit() {
    this.getScale();
  }
  // 加载资产规模统计图表
  getScale() {
    let that = this;
    new Promise((resolve, reject) => {
      this.scaleService.getScale(this.nFundNo).subscribe(data => {
        if (data) {
          that.dataList = data;
          resolve(data);
        }
      })
    }).then(data => {
      var myChart = echarts.init(document.getElementById("oldageCapitalScale"));
      var option = {
        title: {
          text: '        资产净值/亿元'
        },
        tooltip: {
          trigger: 'axis',
          formatter: function (params) {
            params = params[0];
            var date = new Date(params.name);
            return date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate() + ' : ' + params.value[1];
          },
          axisPointer: {
            animation: false
          }
        },
        xAxis: {
          type: 'time',
          splitLine: {
            show: false
          },
          axisLabel: {
            interval: 0
          }
        },
        yAxis: {
          type: 'value',
          boundaryGap: [0, '30%'],
          splitLine: {
            show: false
          }
        },
        series: [{
          name: '数据',
          type: 'line',
          smooth: true,
          showSymbol: false,
          hoverAnimation: true,
          data: that.dataList
        }]
      };
      myChart.setOption(option);
    })
  }
}
